package io.wongd.lib_douyin.db

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

@Dao
interface DouyinDao {

    @Query("SELECT * FROM douyin")
    fun loadAll(): Flow<List<DouyinBean>>

    @Query("SELECT * FROM douyin WHERE aweme_id IN (:awemeIDs)")
    fun loadAllByIds(vararg awemeIDs: String): List<DouyinBean>

    @Query("SELECT * FROM douyin WHERE author_id = :authorID")
    fun loadByAuthorID(authorID: String): List<DouyinBean>

    @Query("SELECT * FROM douyin WHERE author_id = :authorID and max_cursor = :maxCursor")
    fun loadByAuthorIDAndMaxCursor(authorID: String, maxCursor: Long): List<DouyinBean>

    @Query("SELECT max_cursor FROM douyin WHERE author_id = :authorID order by max_cursor desc limit 1")
    fun loadAuthMaxCursor(authorID: String): Long

    @Insert
    fun insertAll(vararg users: DouyinBean)

    @Insert
    fun insertAll(users: List<DouyinBean>)

    @Delete
    fun delete(user: DouyinBean)

    @Query("SELECT * FROM douyin WHERE aweme_id  = :awemeID")
    fun updateVideoUrlById(awemeID: String): Int

}
